﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using BlueMarineWebClient.BlueMarineService;
using BlueMarineWebClient.DO;

namespace BlueMarineWebClient
{
    public partial class Promotion : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["proID"] == null)
            {
                LoadListPromotion();
            }
            else
            {
                lblResult.Text = "<a href='/Promotion.aspx'>View All Promotions</a>";
                LoadPromotionDetail(int.Parse(Request.QueryString["proID"]));
            }
        }

        protected void LoadPromotionDetail(int proID)
        {
            try
            {
                List<vSubPromotionDetail> listPromotionDetail = ServiceBool.ExService.PromotionDetailsGetByPromotionId(proID);
                if (listPromotionDetail.Count == 0)
                    lblResult.Text = "No Detail";
                else
                {
                    dlPromotionDetail.DataSource = listPromotionDetail;
                    dlPromotionDetail.DataBind();
                    lblResult.Text = "Load Complete";
                }
            }
            catch (Exception ex)
            {
                lblResult.Text = "ERROR" + ex.Message;
            }
        }

        protected void LoadListPromotion()
        {
            try
            {
                List<vSubPromotion> listPromotion = ServiceBool.ExService.PromotionsGet(true);
                if (listPromotion.Count == 0)
                    lblResult.Text = "No Promotion";
                else
                {
                    dlPromotion.DataSource = listPromotion;
                    dlPromotion.DataBind();
                    lblResult.Text = "Load Complete";
                }
            }
            catch (Exception ex)
            {
                lblResult.Text = "ERROR" + ex.Message;
            }
        }
    }
}